package com.example.mbl.controller;

import com.example.mbl.dto.StudentDto;
import com.example.mbl.entity.Alumni;
import com.example.mbl.entity.Student;
import com.example.mbl.interceptor.AppToken;
import com.example.mbl.result.PageResult;
import com.example.mbl.result.WebRestResult;
import com.example.mbl.result.business.AlumniPageResult;
import com.example.mbl.result.business.StudentPageResult;
import com.example.mbl.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("Student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @AppToken
    @PostMapping("addStudent")
    public WebRestResult addStudent(@RequestBody Student student){
        WebRestResult result = studentService.addStudent(student);
        return result;
    }

    @AppToken
    @PostMapping("addStudentBatch")
    public WebRestResult addStudentBatch(@RequestBody StudentDto studentDto){
        WebRestResult result = studentService.addStudentBatch(studentDto);
        return result;
    }

    @AppToken
    @PostMapping("deleteStudent")
    public WebRestResult deleteStudent(@RequestBody Student student){
        WebRestResult result = studentService.deleteStudent(student);
        return result;
    }

    @AppToken
    @PostMapping("updateStudent")
    public WebRestResult updateStudent(@RequestBody Student student){
        WebRestResult result = studentService.updateStudent(student);
        return result;
    }

    @AppToken
    @PostMapping("setStudentVisible")
    public WebRestResult setStudentVisible(@RequestBody Student student){
        WebRestResult result = studentService.setStudentVisible(student);
        return result;
    }

    @GetMapping("getStudentList")
    public PageResult<StudentPageResult> getStudentList(String year,String degree,int page,int pagesize){
        PageResult<StudentPageResult> result = studentService.getStudentList(year,degree,page,pagesize);
        return result;
    }

    @AppToken
    @PostMapping("addAlumni")
    public WebRestResult addAlumni(@RequestBody Alumni alumni){
        WebRestResult result = studentService.addAlumni(alumni);
        return result;
    }

    @AppToken
    @PostMapping("addAlumniBatch")
    public WebRestResult addAlumniBatch(@RequestBody StudentDto studentDto){
        WebRestResult result = studentService.addAlumniBatch(studentDto);
        return result;
    }

    @AppToken
    @PostMapping("deleteAlumni")
    public WebRestResult deleteAlumni(@RequestBody Alumni alumni){
        WebRestResult result = studentService.deleteAlumni(alumni);
        return result;
    }

    @AppToken
    @PostMapping("updateAlumni")
    public WebRestResult updateAlumni(@RequestBody Alumni alumni){
        WebRestResult result = studentService.updateAlumni(alumni);
        return result;
    }

    @AppToken
    @PostMapping("setAlumniVisible")
    public WebRestResult setAlumniVisible(@RequestBody Alumni alumni){
        WebRestResult result = studentService.setAlumniVisible(alumni);
        return result;
    }

    @GetMapping("getAlumniList")
    public PageResult<AlumniPageResult> getAlumniList(String year, int page, int pagesize){
        PageResult<AlumniPageResult> result = studentService.getAlumniList(year,page,pagesize);
        return result;
    }
}
